﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class Add : MonoBehaviour {

    private Button btn;
    public GameObject parent;
    public InputField title, detail;
    public GameObject newtit;
    public GameObject newdet;
    public GameObject buttom;

    // Use this for initialization
    void Start () {
        btn = this.gameObject.GetComponent<Button>();
        btn.onClick.AddListener(OnClick);
    }
	
	// Update is called once per frame
	void Update () {
		
	}

    void OnClick()
    {
        if(title.text != "" && detail.text != "")
        {
            //在公告板上创建新的公告

            //new title
            GameObject Title = Instantiate(newtit);
            Title.transform.SetParent(parent.transform);

            //new detail
            GameObject Detail = Instantiate(newdet);
            Detail.transform.SetParent(parent.transform);


            //输入title和detail中的text
            Title.GetComponent<Button>().GetComponentInChildren<Text>().text = title.text;
            Title.GetComponent<Butlletin>().text = Detail.GetComponent<Text>();
            Title.GetComponent<Butlletin>().text.text = detail.text;


            //bottom下移
            GameObject bottom = GameObject.Find("Bottom");
            Destroy(bottom);
            GameObject newBot = Instantiate(buttom);
            newBot.transform.SetParent(parent.transform);
            newBot.name = "Bottom";
        }
    }

}
